/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 *
 * 			http://www.kkkd.com/
 *
 * ========================================================
 */
package com.simon.mengkou.ui.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.ouertech.android.agm.lib.base.utils.UtilList;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.Banner;
import com.simon.mengkou.data.bean.base.Image;
import com.simon.mengkou.data.bean.base.Product;
import com.simon.mengkou.data.enums.EBannerType;
import com.simon.mengkou.data.enums.EEventId;
import com.simon.mengkou.system.global.OuerApplication;
import com.simon.mengkou.system.global.OuerDispatcher;
import com.simon.mengkou.ui.view.BasePagerAdapter;
import com.simon.mengkou.utils.UtilOuer;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author : Zhenshui.Xia
 * @since : 2016/3/22.
 * desc    :
 */
public class HomeBannerAdapter extends BasePagerAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<Banner> mList;

    public HomeBannerAdapter(Context context, List<Banner> datas) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mList = datas;
    }

    @Override
    public int getCount() {
        return UtilList.getCount(mList);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == (View) object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        final Banner data = mList.get(position);
        View convertView = mInflater.inflate(R.layout.layout_home_banner_image_item, null);
        SimpleDraweeView sdvImage = (SimpleDraweeView) convertView.findViewById(R.id.image_id_image);
        OuerApplication.mImageLoader.loadImage(sdvImage, data.getImage().getUrl());
        sdvImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MobclickAgent.onEvent(mContext, EEventId.HOME_BANNER);
                switch (data.getType()) {
                    case EBannerType.BANNER_ACTIVITY:
                        OuerDispatcher.presentWebActivity(mContext, data.getRelateId(), null);
                        break;
                    case EBannerType.BANNER_PRODUCT:
                        OuerDispatcher.presentProductDetailActivity(mContext, data.getRelateId());
                        break;
                    case EBannerType.BANNER_SHARE_ORDER:
                        OuerDispatcher.presentShareOrderDetailActivity(mContext, data.getRelateId());
                        break;
                    case EBannerType.BANNER_TOPIC:
                        OuerDispatcher.presentWebTopicDetailActivity(mContext, data.getRelateId());
                        break;
                    default:
                        break;
                }
            }
        });
        container.addView(convertView);
        return convertView;
    }
}
